package com.atguigu.spark.util.util

import com.alibaba.druid.pool.DruidDataSourceFactory

import java.sql.Connection
import java.util.Properties
import javax.sql.DataSource

object DruidUtil {
    var dataSource: DataSource = init()

    //初始化连接池方法
    def init(): DataSource = {
      val properties = new Properties()
      properties.setProperty("driverClassName", "com.mysql.jdbc.Driver")
      properties.setProperty("url", PropUtil("jdbc.url"))
      properties.setProperty("username", PropUtil("jdbc.user"))
      properties.setProperty("password", PropUtil("jdbc.password"))
      properties.setProperty("maxActive", PropUtil("jdbc.datasource.size"))
      DruidDataSourceFactory.createDataSource(properties)
    }

    //获取MySQL连接
    def getConnection: Connection = {
      dataSource.getConnection
    }


}
